﻿

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>通道数据</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type ="text/javascript">


	Ext.onReady(function()
	{
		//Ext.namespace("com.group1");
		var grid ;
		var win_update ;
		var win_add;
		var store;

		
		var ht = Ext.get("main_tree").getHeight() -25;
		
		var addImg = getAddImg();
		var updateImg =getUpdateImg();
		var delImg =getDelImg();
		
		var txt_fbegttime= new Ext.form.DateField({
		name: "f_begtime"							
		}); 
		
		var txt_fendtime= new Ext.form.DateField({
						name: "f_endtime"						
						}); 
		
		var toolBar1 = new Ext.Toolbar(
		{
			items:
			[
				
				{
					xtype:'tbbutton',
					text:"通道历史数据",
					icon:updateImg,cls:"x-btn-text-icon", 
					cls: "x-btn-text-icon",
					handler: function()
					{
						//判断是否有选择行
						
						var selModel = grid.getSelectionModel();
						var record;//选择的行的数据
						if(!selModel.hasSelection())
						{
							Ext.Msg.alert("错误", "请选择要操作的行!");
						}
						else if(selModel.getSelections().length > 1)
						{
							Ext.Msg.alert("错误", "一次只能操作一行,不行同时操作多行!");
						}
						else
						{
							record = selModel.getSelected();
							
							var txt_fbegttime2= new Ext.form.DateField({
							name: "f_begtime2"							
							}); 
							
							var txt_fendtime2= new Ext.form.DateField({
											name: "f_endtime2"						
											}); 
											
							var toolBar2 = new Ext.Toolbar({
								items:
								[
									'开始日期',txt_fbegttime2,
									'结束日期',txt_fendtime2,
									{
										xtype:'tbbutton',
										text:'导出EXCEL',
										icon:addImg,cls:"x-btn-text-icon" , 
										cls: "x-btn-text-icon",
										handler: function()
										{ 
											var pstarttime;
											var pendtime;
					
											pstarttime = txt_fbegttime2.getValue().dateFormat('Y-m-d').toString();
											pendtime = txt_fendtime2.getValue().dateFormat('Y-m-d').toString();
										
											if(pstarttime.localeCompare(pendtime)>=0)
											{
												Ext.Msg.alert("导出EXCEL","开始时间必须小于结束时间");
												
											}else
											{
												window.location.href ='Json/CurrDataAction!export2?'
													+"&p_id="+record.get("id")
													+"&p_starttime="+pstarttime
													+"&p_endtime="+pendtime;	
											}
					
										}
									}
								]
							});
							
							
							var sm_userlist = new Ext.grid.CheckboxSelectionModel();
							
							var cm_userlist = new Ext.grid.ColumnModel(
							[
			
								new Ext.grid.RowNumberer(),
								sm_userlist,
								{header: "历史数据", width: 80, dataIndex: "chn_data"},
								{header: "历史状态", width: 80, dataIndex: "chn_state"},
								{id: "createtime", header: "上传时间", dataIndex: "createtime"}
								
							]);

		
		
							var proxy_userlist = new Ext.data.HttpProxy({url: "Json/CurrDataAction!list2?p_id="+record.get("id")});
							//Record	定义记录结果
							var AGENTER_USERLIST = Ext.data.Record.create([
								{name: "chn_data", type: "string", mapping: "chn_data"},
								{name: "chn_state", type: "string", mapping: "chn_state"},
								{name: "createtime", type: "string", mapping: "createtime"}
							]);
		
		
							var reader_userlist = new Ext.data.JsonReader(
							{totalProperty: "totalProperty", root: "root"},   
							AGENTER_USERLIST 
							);

							//Store
							store_userlist = new Ext.data.Store
							({
							proxy: proxy_userlist,
							reader: reader_userlist
							});
		
							store_userlist.load({params: {start: 0, limit: 10}});

							grid_userlist = new Ext.grid.GridPanel({
								region:'center',
								//title: "中国公民",
								width:600,
								height:300,
								cm: cm_userlist,
								sm: sm_userlist,
								store: store_userlist,
			
								autoExpandColumn: "createtime", //自动伸展，占满剩余区域
							
								bbar: new Ext.PagingToolbar({
										store: store_userlist, //这个不用介绍了吧？
										pageSize: 10,//页大小
										displayInfo: true,//是否显示 displayMsg
										displayMsg: "本页显示第{0}条到第{1}条的记录,一共{2}条",
										emptyMsg: "没有记录"//如果没有记录，则显示该文本
									}),
								listeners:
								{
									'rowdblclick' : function(grid, rowIndex, e)
									{  
										
										
					
										
									}
								}
			
							});	
		
							

							win_userlist = new Ext.Window({
									title: "通道历史数据",
									width: 600,
									modal: true,
									autoHeight: true,
									tbar:toolBar2,
									items: [grid_userlist]
									}); 

							win_userlist.show();
						}
					}

				},'-',
				'开始日期',txt_fbegttime,
				'结束日期',txt_fendtime,
				{
					xtype:'tbbutton',
					text:'导出EXCEL',
					icon:addImg,cls:"x-btn-text-icon" , 
					cls: "x-btn-text-icon",
					handler: function()
					{ 
							var rows = grid.getSelectionModel().getSelections();// 返回值为 Record 数组
							if(rows.length==0)
							{
								Ext.MessageBox.alert('警告', '最少导出一条记录!');
							}
							else
							{
								var ids="";
								for (var i = 0; i < rows.length; i++) 
								{
									ids =ids + rows[i].get("id") +"-";
								}
								var pstarttime;
								var pendtime;
		
								pstarttime = txt_fbegttime.getValue().dateFormat('Y-m-d').toString();
								pendtime = txt_fendtime.getValue().dateFormat('Y-m-d').toString();
							
								if(pstarttime.localeCompare(pendtime)>=0)
								{
									Ext.Msg.alert("导出EXCEL","开始时间必须小于结束时间");
									
								}else
								{
									window.location.href ='Json/CurrDataAction!export2?'
															+"&p_id="+ids
															+"&p_starttime="+pstarttime
															+"&p_endtime="+pendtime;		
								}	
							
							}	
							
						
						}


					}
				
			]
		});
		
		
		var sm = new Ext.grid.CheckboxSelectionModel();
		
		var cm = new Ext.grid.ColumnModel(
		[
			
			new Ext.grid.RowNumberer(),
			sm,
			{header: "单位名称", width: 120, dataIndex: "unit_name"},
			{header: "更新时间", width: 200, dataIndex: "updateTime"},			
			{header: "通道名称", width: 100, dataIndex: "chn_name"},
			{header: "通道编号", width: 120, dataIndex: "id"},
			{header: "最新数据", width: 100, dataIndex: "lastData"},			
			{header: "通道状态", width: 100, dataIndex: "chn_state"},
			{header: "模块名称", width: 120, dataIndex: "mod_name"},
			{header: "串口名称", width: 120, dataIndex: "com_name"},
			{id: "app_name",header: "现场程序名称", width: 120, dataIndex: "app_name"}
		]);

		
		
		var proxy = new Ext.data.HttpProxy({url: "Json/ChannelAction!listData"});
		//Record	定义记录结果
		var Manager = Ext.data.Record.create([
			{name: "id", type: "string", mapping: "id"},
			{name: "chn_name", type: "string", mapping: "chn_name"},
			{name: "lastData", type: "string", mapping: "lastData"},
			{name: "updateTime", type: "string", mapping: "updateTime"},
			{name: "chn_state", type: "string", mapping: "chn_state"},
			{name: "mod_name", type: "string", mapping: "mod_name"},
			{name: "com_name", type: "string", mapping: "com_name"},
			{name: "app_name", type: "string", mapping: "app_name"},
			{name: "unit_name", type: "string", mapping: "unit_name"}
		]);
		
		
		var reader = new Ext.data.JsonReader(
		{totalProperty: "totalProperty", root: "root"},   
		Manager 
		);

		//Store
		store = new Ext.data.Store
		({
		proxy: proxy,
		reader: reader
		});
		//store.load();
		store.load({params: {start: 0, limit: 10}});

		grid = new Ext.grid.GridPanel({
			region:'center',
			//title: "中国公民",
			width:600,
   			height:300,
			cm: cm,
			sm: sm,
			store: store,
			//renderTo: "group1_managelist",
			autoExpandColumn: "app_name", //自动伸展，占满剩余区域
			tbar:toolBar1,
			bbar: new Ext.PagingToolbar({
					store: store, //这个不用介绍了吧？
					pageSize: 10,//页大小
					displayInfo: true,//是否显示 displayMsg
					displayMsg: "本页显示第{0}条到第{1}条的记录,一共{2}条",
					emptyMsg: "没有记录"//如果没有记录，则显示该文本
				}),
			listeners:
			{

			}
			
		});	
		
		grid.getStore().on("remove", function(s, record, index)
		{		
			var jsonArray = [record.data];
			Ext.Ajax.request({
			method: "post",
			url: "Json/ChannelAction!delete",
			params: {f_data: Ext.util.JSON.encode(jsonArray)},
			success:function(response,opts) 
			{
			
				var jsonObj=Ext.util.JSON.decode(response.responseText );
				if(jsonObj.success==true)
				{
					store.reload();
					Ext.Msg.alert("成功", "删除成功!");
					
				}
				else
				{
					store.reload();
					Ext.Msg.alert("删除失败",jsonObj.msg);
					
				}
				
			}
			
			});
		});  

		
		
		var panel1 = new Ext.Panel({
		 //layout:'border',
		 layout:'fit',//自适应
  		items: [grid],
		//title:"最简单的面板11111111",
		//width:600,
		height:ht,
		titleCollapse:true,
		collapsible:false,
		renderTo:"channelInfo_list"
		});
		
	});	
	
			
	</script>
  </head>
  
  <body>
     <div id="channelInfo_list"></div>
  </body>
</html>
